﻿using System;
using System.Text.RegularExpressions;
using UnityEngine;

namespace BF
{
    public class EmailUtil
    {
        public static void Send(string toEmail, string subject = "", string body = "")
        {
            string uriString = $"mailto:{toEmail}?subject={subject}&body={body}";
            Uri uri = new Uri(uriString);
            Application.OpenURL(uri.AbsoluteUri);
        }

        public static bool IsEmail(string email)
        {
            //如果为空，认为验证不合格
            if (string.IsNullOrEmpty(email))
            {
                return false;
            }
            //模式字符串
            string pattern = @"^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$";
            Regex regex = new Regex(pattern);
            return regex.IsMatch(email.Trim());
        }
    }
}